package dao;

import domain.Member;
import domain.Orders;
import domain.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Freedy
 * @date 2020/12/23 19:59
 */
public interface IOrdersDao {

    /**
     * 查找所有订单
     * @return
     * @throws Exception
     */
    @Select("select * from orders")
    @Results({
            @Result(id=true,property = "id",column = "id"),
            @Result(property = "orderNum",column = "orderNum"),
            @Result(property = "orderTime",column = "orderTime"),
            @Result(property = "peopleCount",column = "peopleCount"),
            @Result(property = "orderDesc",column = "orderDesc"),
            @Result(property = "orderStatus",column = "orderStatus"),
            @Result(property = "payType",column = "payType"),
            @Result(property = "product",column = "productId",javaType = Product.class,one=@One(
                    select = "dao.IProductDao.findById"
            ))

    })
    List<Orders> findAll() throws Exception;

    /**
     * 根据id查询订单,并查询与其有关的其他所有表的信息
     * @param id
     * @return
     * @throws Exception
     */
    @Select("select * from orders where id=#{id}")
    @Results({
            @Result(id=true,property = "id",column = "id"),
            @Result(property = "orderNum",column = "orderNum"),
            @Result(property = "orderTime",column = "orderTime"),
            @Result(property = "peopleCount",column = "peopleCount"),
            @Result(property = "orderDesc",column = "orderDesc"),
            @Result(property = "orderStatus",column = "orderStatus"),
            @Result(property = "payType",column = "payType"),
            @Result(property = "product",column = "productId",javaType = Product.class,one=@One(
                    select = "dao.IProductDao.findById"
            )),
            @Result(property = "member",column = "memberId",javaType = Member.class,one=@One(
                    select = "dao.IMemberDao.findById"
            )),
            @Result(property = "travellers",column = "id",javaType = java.util.List.class,many=@Many(
                    select = "dao.ITravellerDao.findByOrdersId"
            ))

    })
    Orders findById(int id) throws Exception;
}
